package cn.lianxi.kaoshi._11_;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class TokenizerMapper extends
		Mapper<LongWritable, Text, Text, IntWritable> {

	IntWritable one = new IntWritable(1);
	Text k = new Text();

	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		// 业务代码
		// 1.切分行数据
		String[] words = value.toString().split(" ");
		// 2.将每个单词封装成<k,v>
		for (String word : words) {
			k.set(word);
			// 3.输出<k,v>
			context.write(k, one);
		}
	}
}
